package com.example.service.impl;

import com.example.entity.Student;
import com.example.mapper.StudentMapper;
import com.example.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {


    StudentMapper studentMapper;
    @Autowired
    public void setStudentMapper(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }

    @Override
    public Student findById(int id) {
        Student byId = studentMapper.findById(id);
        return byId;
    }

    @Override
    public PageInfo<Student> findAllByPage(Student student, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> allByPage = studentMapper.findAllByPage(student);
        PageInfo<Student> pageInfo = new PageInfo<>(allByPage);
        return pageInfo;
    }


    @Override
    public int insert(Student student) {
        int insert = studentMapper.insert(student);
        return insert;
    }

    @Override
    public int update(Student student) {
        int update = studentMapper.update(student);
        return update;
    }

    @Override
    public int delete(int id) {
        int delete = studentMapper.delete(id);
        return delete;
    }
}
